package com.wxx.service;

import java.util.concurrent.ConcurrentHashMap;

import org.springframework.stereotype.Component;

import net.sf.cglib.reflect.FastClass;

@Component
public class IfastClassImpl implements IfastClass {

	private volatile ConcurrentHashMap<String, FastClass> cache = new ConcurrentHashMap<String, FastClass>();

    @Override
    public void init()
    {
    }

    @Override
    public FastClass get(String className)
    {
        FastClass fastClass = cache.get(className);
        if(fastClass == null){
            try
            {
                fastClass =  FastClass.create(Class.forName(className));
            } catch (ClassNotFoundException e)
            {
               System.out.println("<><><><><><><><><>");
            }
            this.add(className, fastClass);
        }
        return fastClass;
    }

    @Override
    public void add(String className, FastClass fastClass)
    {
        cache.putIfAbsent(className, fastClass);

    }

    @Override
    public void reload()
    {
        cache = new ConcurrentHashMap<String, FastClass>();
    }


}
